﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;

namespace RescueRobotController.Panels
{
    public partial class DataDisplayPanel : DockContent
    {
        public Dictionary<string, string> dataList = null;

        // 下面的内容是每个面板必须要有的
        // *********** BEGIN ************* //
        // “发送AT指令”事件
        public delegate void ExistATCmdToSendHandler(ATCmd cmd);
        public event ExistATCmdToSendHandler SendATCmd;

        // 处理AT指令
        public void HandleATCmd(ATCmd cmd)
        {
            string target;
            string value;

            if (cmd.type != ATCmdType.SET) return;

            target = cmd.target;
            value = cmd.value;

            if (!dataList.ContainsKey(target))
            {
                dataList.Add(target, value);
            }
            else
            {
                dataList[target] = value;
            }

            UpdateListView();
        }
        // *********** END ************* //

        public void UpdateListView()
        {
            int cnt = 0;
            listView_data.Items.Clear();
            foreach(string key in dataList.Keys)
            {
                ListViewItem item = new ListViewItem();
                item.Text = (cnt + 1).ToString();
                item.SubItems.Add(key);
                item.SubItems.Add(dataList[key]);

                listView_data.Items.Add(item);

                cnt++;
            }
        }

        public DataDisplayPanel()
        {
            InitializeComponent();
            dataList = new Dictionary<string, string>();
        }
    }
}
